package com.soso.base.util.json;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.soso.base.util.other.JsonUtil;
public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
		String name="<img src=\\";
		System.out.println(name);
		
		TestBean bean=new TestBean();
		bean.setName(name);
		
		String str[]={"<img src=\\\""};
		GsonBuilder gsonBuilder = new GsonBuilder();
		gsonBuilder.serializeNulls();
		Gson gson = gsonBuilder.create();
		String json=gson.toJson(str);
		System.out.println(json);
		JsonUtil<String[]> jsonUtil=new JsonUtil<String[]>(){};
		str=jsonUtil.fromJsonToObject(json);
		
		System.out.println(str[0]);
	}
	public static void test2(){
		String name="\"date\":\"";
		System.out.println(name);
		TestBean bean=new TestBean();
		bean.setName(name);
		
		List<TestBean> list=new ArrayList<TestBean>();
		list.add(bean);
		
		Gson gson = new Gson();
		String json = gson.toJson(list);
		System.out.println(json);
		Type collectionType = new TypeToken<List<TestBean>>(){}.getType();
		list=gson.fromJson(json, collectionType);
		for(TestBean beanTemp:list){
			System.out.println(beanTemp.getName());
		}
	}
}
